﻿@model IList<LogEntity>
	<div class="layui-card">
		<div class="layui-form layui-card-header layuiadmin-card-header-auto" style="padding-top:0px;padding-bottom:0px;">
			<div class="layui-form-item">
				<div class="layui-inline" style="margin-right: 0;">
					<label class="layui-form-label" style="padding:0px;padding-right: 5px;width:100px;">
						<select id="dropSearchName" name="dropSearchName">
							<option value="Title">标题</option>
							<option value="UserName">操作人</option>
							<option value="UserIP">IP地址</option>
						</select>
					</label>
					<div class="layui-input-inline" style="margin: 0px;">
						<input type="text" class="layui-input" id="txtSearchKeyword" name="txtSearchKeyword" placeholder="请输入搜索关键字" autocomplete="off" onkeypress="javascript:return DefaultButton(event, 'btnSearch')">
					</div>
				</div>
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="btnSearch">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
				</div>
			</div>
		</div>

		<div class="layui-card-body">
			<div class="layui-tab layui-tab-brief" lay-filter="tabList">
				<ul class="layui-tab-title">
					<li lay-id="-1" class="layui-this">全部</li>
					<li lay-id="0">常规记录</li>
					<li lay-id="1">登录成功</li>
					<li lay-id="2">登录失败</li>
					<li lay-id="3">退出登录</li>
					<li lay-id="4">越权操作</li>
					<li lay-id="5">异常记录</li>
					<li lay-id="6">管理错误</li>
					<li lay-id="7">重大行为</li>
					<li lay-id="8">系统行为</li>
				</ul>
				<div class="layui-tab-content">
					<table id="tblList" lay-filter="tblList"></table>
				</div>
			</div>
			<input type="hidden" id="hidTab" value="-1" />
			<script type="text/html" id="toolbarHead">
				<div class="layui-form">
					<div class="layui-form-item" style="margin: auto;">
						<div class="layui-inline">
							<div class="layui-input-inline layui-input-company"><strong>删除</strong></div>
							<div class="layui-input-inline">
								<select id="dropOffSet">
									<option value="0">请选择你要进行的操作</option>
									<option value="-7">一个星期前的</option>
									<option value="-15">半个月前的</option>
									<option value="-30">一个月前的</option>
									<option value="1">最后一万条</option>
									<option value="10">最后十万条</option>
								</select>
							</div>
							<div class="layui-input-inline">
								<select id="dropLogCategory">
									<option value="-1">所有类型</option>
									<option value="0">常规类型</option>
									<option value="1">登录成功</option>
									<option value="2">登录失败</option>
									<option value="3">登录退出</option>
									<option value="4">越权操作</option>
									<option value="5">异常记录</option>
									<option value="6">管理错误</option>
									<option value="7">重大行为</option>
									<option value="8">系统行为</option>
								</select>
							</div>
							<div class="layui-input-inline layui-input-company">
								<strong>日志</strong>
								<button class="layui-btn layuiadmin-btn-list" onclick="OffSetDel()">执行选定的操作</button>
							</div>
						</div>
						<div class="layui-inline">
							<button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="btnDeleteMulti">批量删除</button>
							<button class="layui-btn layuiadmin-btn-list" onclick="DelLogAll()">清空日志</button>
						</div>
					</div>
				</div>
				
			</script>
			<script type="text/html" id="statusText">
				{{#  if(d.Category == 0){ }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">常规记录</button>
				{{#  } else if(d.Category == 1){ }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">登录成功</button>
				{{#  } else if(d.Category == 2){ }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">登录失败</button>
				{{#  } else if(d.Category == 3){ }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">退出登录</button>
				{{#  } else if(d.Category == 4){ }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">越权操作</button>
				{{#  } else if(d.Category == 5){ }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">异常记录</button>
				{{#  } else if(d.Category == 6){ }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">管理错误</button>
				{{#  } else if(d.Category == 7){ }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">重大行为</button>
				{{#  } else if(d.Category == 8){ }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">系统行为</button>
				{{#  } else{ }}
				<button class="layui-btn layui-btn-primary layui-btn-xs">未分类</button>
				{{#  } }}
			</script>
			<script type="text/html" id="tblBarCol">
				<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-search"></i>查看</a>
			</script>
		</div>
	</div>
@Html.AntiForgeryToken()
@section scripts {
	<script type="text/javascript">
		layui.use(['form', 'table', 'element'], function () {
			var table = layui.table;
			var form = layui.form;
			var element = layui.element;

			//获取hash来切换选项卡，假设当前地址的hash为lay-id对应的值
			var layid = location.hash.replace(/^#tabList=/, '');
			if (layid != null && layid != "") {
				element.tabChange('tabList', layid);
				$("#hidTab").val(layid);
			}
			//监听Tab切换，以改变地址hash值
			element.on('tab(tabList)', function () {
				location.href = location.pathname + "#tabList=" + this.getAttribute('lay-id');
				window.location.reload();
			});

			//加载表格
			table.render({
				elem: '#tblList'
				, url: '/Admin/SiteConfig/GetLogManager'
				, toolbar: '#toolbarHead'
				, where: GetSearchParam()
				, request: {
					pageName: 'PageNum' //页码的参数名称，默认：page
					, limitName: 'PageSize' //每页数据量的参数名，默认：limit
				}
				, cols: [[
					{ type: "checkbox", width: 30, fixed: "left", align: 'center' },
					{ field: 'Title', minWidth: 150, title: '标题', align: 'left' },
					{ field: 'Category', width: 100, title: '类型', align: 'center', templet: '#statusText' },
					{ field: 'ScriptName', minWidth: 150, title: '访问地址', align: 'left' },
					{ field: 'Timestamp', width: 180, title: '操作时间', align: 'center', templet: function (d) { return (d.Timestamp == null ? "" : (formatDateTime(d.Timestamp) == "9999-12-31 23:59:59") ? "" : formatDateTime(d.Timestamp)); } },
					{ field: 'UserIP', width: 150, title: 'IP地址', align: 'center' },
					{ field: 'UserName', width: 100, title: '操作人', align: 'center' },
					{ field: 'LogID', title: '操作', width: 100, fixed: "right", align: "center", templet: '#tblBarCol' }
				]]
				, parseData: function (res) { //res 即为原始返回的数据
					return {
						"code": 0, //解析接口状态
						"msg": "", //解析提示文本
						"count": res.RecordTotal, //解析数据长度
						"data": res.RowList //解析数据列表
					};
				}
				, limits: [10, 15, 20, 25, 50, 100]
				, limit: 10
				, page: true
			});
			//监听表格操作列
			table.on('tool(tblList)', function (obj) {
				if (obj.event === 'view') {
					layer_show('查看日志', '/Admin/SiteConfig/ViewLog?id=' + obj.data.LogID);
					return false;
				}
			});
			//监听搜索操作
			form.on('submit(btnSearch)', function (data) {
				reloadTable();
				return false;
			});
			//监听批量删除
			form.on('submit(btnDeleteMulti)', function (data) {
				var checkStatus = table.checkStatus('tblList');
				var data = checkStatus.data;
				var ids = "";
				for (j = 0, len = data.length; j < len; j++) {
					if (j < len - 1) {
						ids += data[j].LogID + ',';
					} else {
						ids += data[j].LogID;
					}
				}
				DeleteMulti(ids, '/Admin/SiteConfig/DelLogMulti');
				return false;
			});

			//表格重载
			function reloadTable(tableID = 'tblList') {
				table.reload(tableID, {
					page: {
						curr: 1
					}
					, where: GetSearchParam()
				}, 'data');
			}
		});
		function GetSearchParam() {
			var SearchName = $("#dropSearchName").val();
			var SearchKeyword = $("#txtSearchKeyword").val();
			var TabStatus = $("#hidTab").val();
			var objParam = { "SearchName": SearchName, "SearchKeyword": SearchKeyword, "TabStatus": TabStatus };
			return objParam;
		}
		function OffSetDel() {
			var OffSet = $("#dropOffSet").val();
			var LogCategory = $("#dropLogCategory").val();
			if (OffSet == "0") {
				layer.alert('请选择你要进行的操作!');
				return;
			}
			//询问框
			layer.confirm("您确认删除选定的记录吗？", {
				btn: ["确定", "取消"]
			}, function () {
				var sendData = { "OffSet": OffSet, "LogCategory": LogCategory };
				var url = "/Admin/SiteConfig/OffSetDelLog";
				$.ajax({
					type: "Post",
					url: url,
					data: sendData,
					headers: {
						"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
					},
					error: function (data, status, e) {
						layer.alert('操作失败!');
					},
					success: function (data) {
						if (data.Result == "ok") {
							layer.alert('操作成功!');
							setTimeout('window.location.reload()', 1000);
						}
						else {
							layer.alert(data.Result);
						}
					}
				});
			});
		}
		function DelLogAll() {
			//询问框
			layer.confirm("您确认删除选定的记录吗？", {
				btn: ["确定", "取消"]
			}, function () {
				var url = "/Admin/SiteConfig/DelLogAll";
				$.ajax({
					type: "Post",
					url: url,
					data: null,
					headers: {
						"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
					},
					error: function (data, status, e) {
						layer.alert('操作失败!');
					},
					success: function (data) {
						if (data.Result == "ok") {
							layer.alert('操作成功!');
							setTimeout('window.location.reload()', 1000);
						}
						else {
							layer.alert(data.Result);
						}
					}
				});
			});
		}
	</script>
}